package com.my.encoding;

import com.my.HttpFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by YJH on 2017/7/12 17:34.
 */
public class EncodingFilter extends HttpFilter {

    private String encoding;

    @Override
    protected void init() {
        encoding = getFilterConfig().getServletContext().getInitParameter("encoding");
    }

    @Override
    public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException {

        System.out.println("EncodingFilter--->doFilter()");

        request.setCharacterEncoding(encoding);
        filterChain.doFilter(request, response);
    }

}
